'''
Created on May 7, 2012
TC ID: Ecom_5035
Desc: Kiem thu chuc nang them quy dinh bai hoc
@author: lavang
'''
import unittest
import time
from HTMLTestRunner import HTMLTestRunner
from Functions.loginPageFunc import login
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.lessonInformationFunc import clickOnLesson,\
    clickOnLessonInformation, clickOnEditRules, clickOnAddCompletionRule,\
    addRule, isRuleAddedSuccessfully
    

username=readData("username",index=2)
password=readData("password",index=2)
tm_lesson='Python'
tm_rule1='Seen all units'
tm_rule2='Seen a fraction of units'
tm_rule3='Seen a specific unit'
tm_relation='and'
tm_unit='unit 3'
tm_percentage='60'
class Ecom_5035(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5035(self):
        print "Buoc 1: Dang nhap website"
        login(self,username,password)
        
        print "Buoc 2: Click vao bai hoc"
        clickOnLesson(self,tm_lesson)
        
        print "Buoc 3: Click vao 'Lesson information' "
        clickOnLessonInformation(self)
        
        print "Buoc 4: Click vao 'Edit rule' "
        clickOnEditRules(self)
        
        print "Buoc 5: Click 'Add completion rule' "
        clickOnAddCompletionRule(self)
        
        print "Buoc 6: Them quy dinh cho bai hoc"
        addRule(self,tm_rule3,tm_relation,tm_percentage,unit=tm_unit,edit='off')
        
        print "Buoc 7: Xac nhan bai hoc duoc them quy dinh thanh cong"
        self.assertTrue(isRuleAddedSuccessfully(self,tm_rule3), "Failed!")
        print "Passed! Them quy dinh cho bai hoc thanh cong"
    
    def tearDown(self):
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5035)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang them quy dinh bai hoc'
                    )
    runner.run(suite)